package org.myspringframework.springbootmybatisplus001.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import jakarta.annotation.Resource;
import org.myspringframework.springbootmybatisplus001.service.UserService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author fzy
 * @version 1.0
 * 创建时间：       2024-09-24 19:59
 */

@RestController
@RequestMapping("user")
public class UserController {

    @Resource
    UserService userService;

    @Resource
    ObjectMapper objectMapper;

    @GetMapping("{id}")
    public String getById(@PathVariable Integer id) {
        try {
            return objectMapper.writeValueAsString(userService.getById(id));
        } catch (JsonProcessingException e) {
            throw new RuntimeException(e);
        }
    }
}
